package net.xiaoyu233.mitemod.miteite.gui;

import net.minecraft.*;
import net.xiaoyu233.mitemod.miteite.inventory.container.ContainerFusionmine;
import net.xiaoyu233.mitemod.miteite.tileentity.TileEntityFusionmine;
import org.lwjgl.opengl.GL11;

import java.util.List;

public class GuiFusionmine extends awy implements ICrafting {

    private static final bjo furnaceGuiTextures = new bjo("textures/gui/container/fusion_mine.png");
    private TileEntityFusionmine Fusionmine;

    public GuiFusionmine(EntityPlayer player, TileEntityFusionmine tileEntityFusionmine) {
        super(new ContainerFusionmine(player, tileEntityFusionmine));
        this.Fusionmine = tileEntityFusionmine;
        this.e.onCraftGuiOpened(this);
    }

    @Override
    public void b(int par1, int par2) {
        String var3 = this.Fusionmine.hasCustomName() ? this.Fusionmine.getCustomNameOrUnlocalized() : bkb.a(this.Fusionmine.getCustomNameOrUnlocalized());
        this.o.b(var3, this.c / 2 - this.o.a(var3) / 2, 6, 4210752); // 标题
        this.o.b(bkb.a("container.inventory"), 8, this.d - 96 + 2, 4210752); // 玩家背包标题

        // 检查是否正在合成
        if (this.Fusionmine.getInsynthesis()) {
            int remainingTime =  Math.max(0, (this.Fusionmine.getMaxtime() - this.Fusionmine.getFtick()) / 20);// 剩余时间（秒）
            this.o.b(bkb.a("合成中：剩余 " + remainingTime + " 秒"), 100, this.d - 106, 4210752); // 提示合成剩余时间
        }
        String heatText = "热量值: " + this.Fusionmine.getHeat() + "/1200";
        this.o.b(heatText, 100, this.d - 96 + 2, 4210752); // 在坐标(10,20)显示白色文本

        // 热量不足提示
        if (this.Fusionmine.getHeat() < 200) {
            this.o.b("热量不足！最低200", 100, this.d - 106, 0xFF0000); // 红色提示
        }
    }

    @Override
    public void a(float par1, int par2, int par3) {
        GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
        this.f.J().a(furnaceGuiTextures);
        int var4 = (this.g - this.c) / 2;
        int var5 = (this.h - this.d) / 2;
        this.b(var4, var5, 0, 0, this.c, this.d);

        // 绘制合成进度条
        int Fusionmine = this.Fusionmine.getFtick();
        int Fusionminemaxtime = this.Fusionmine.getMaxtime();
        if (Fusionmine != 0 && Fusionminemaxtime != 0) {
            int progressWidth = (int) (30 * ((float) Fusionmine / Fusionminemaxtime)); // 进度条宽度
            this.b(this.g / 2 + 12, this.h / 2 - 45, 176, 0, progressWidth, 16); // 绘制进度条
        }
    }

    @Override
    public void a(int mouse_x, int mouse_y, float par3) {
        super.a(mouse_x, mouse_y, par3);
    }

    @Override
    public void updateCraftingInventory(Container container, List list) {

    }

    @Override
    public void sendSlotContents(Container container, int i, ItemStack itemStack) {

    }

    @Override
    public void sendProgressBarUpdate(Container container, int id, int value) {
        if (id == 0) {
            Fusionmine.setHeat(value);
        } else if (id == 1) {
            Fusionmine.setFtick(value);
        } else if (id == 2) {
            Fusionmine.setInsynthesis(value == 1);
        } else if (id == 3) {
            Fusionmine.setMaxtime(value);
        }
    }
    @Override//onGuiClosed
    public void b() {
        super.b();
        this.e.b(this);
    }
}